#include "biplTypes.h"
#include <iostream>
#include <sstream>

#include <Magick++.h> 

using namespace Magick; 

const std::string imageTypes::DEFAULT_DIR = "";
const std::string imageTypes::DEFAULT_FILENAME = "bipl";
const std::string imageTypes::DEFAULT_TYPE = ".jpg";

imageTypes::imageTypes(const imageTypes& img) {
	Image * dummy = new Image(*img.im);
	im = dummy;
	fx =img.getX(); fy = img.getY();
	pathname = img.pathname;
	filename = img.filename;
	extension = img.extension;
}
/// load from file name
imageTypes::imageTypes(const std::string &imageSpec_){ 
	im = new Image(imageSpec_);
	fx =0.0f; fy = 0.0f;
	path p(imageSpec_);
	pathname = stringTypes(p.parent_path().string());
	filename = stringTypes(p.stem().string());
	extension = stringTypes(p.extension().string());
}
/// specify size and color
imageTypes::imageTypes(size_t width_, size_t height_, const Color &color_) { 
	const Geometry size(width_, height_);
	im = new Image(size, color_);
	fx =0.0f; fy = 0.0f;
	pathname = stringTypes();
	filename = stringTypes("bipl");
	extension = stringTypes(".jpg");
}

imageTypes::operator bool() const
{
	return (im != NULL);
}

imageTypes::operator boolTypes() const
{
	return toBoolean();
}

boolTypes imageTypes::toBoolean() const
{
	return boolTypes(im != NULL);
}

const imageTypes operator|(const imageTypes& lhs, const pairTypes& rhs) // #
{
	imageTypes translateImage(lhs);
	translateImage.fx += rhs.getX();
	translateImage.fy += rhs.getY();
	return translateImage;
}

const imageTypes operator&(const imageTypes& lhs, const degreeTypes& rhs) // @
{
	imageTypes rotateImage(lhs);
	rotateImage.im->rotate((double)(rhs.getValue()));
	return rotateImage;
}

const imageTypes operator/(const imageTypes& lhs, const pairTypes& rhs)
{
	imageTypes skewImage(lhs);
	skewImage.im->shear((double)rhs.getX(), (double)rhs.getY());
	return skewImage;
}

const imageTypes operator*(const imageTypes& lhs, const pairTypes& rhs)
{
	imageTypes scaleImage(lhs);
	const Geometry size(rhs.getX(),rhs.getY());
	scaleImage.im->resize(size);
	return scaleImage;
}

imageTypes& operator|=(imageTypes& lhs, const pairTypes& rhs)
{
	lhs.fx += rhs.getX();
	lhs.fy += rhs.getY();
	return lhs;
}

imageTypes& operator&=(imageTypes& lhs, const degreeTypes& rhs)
{
	lhs.im->rotate((double)rhs.getValue());
	return lhs;
}

imageTypes& operator*=(imageTypes& lhs, const pairTypes& rhs)
{
	const Geometry size((unsigned int)rhs.getX(),(unsigned int)rhs.getY());
	lhs.im->resize(size);
	return lhs;
}

imageTypes& operator/=(imageTypes& lhs, const pairTypes& rhs)
{
	lhs.im->shear((double)rhs.getX(), (double)rhs.getY());
	return lhs;
}